package cn.itheima.student.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import cn.itheima.student.daomain.Student;
import cn.itheima.student.service.StudentService;
import cn.itheima.student.service.impl.StudentServiceImpl;


public class StudentUpdateServlet1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// 0.处理乱码
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		Student student = new Student();
		Map<String, String[]> map = request.getParameterMap();
		
		try {
			BeanUtils.populate(student, map);
			
			StudentService service = new StudentServiceImpl();
			service.updateStudent(student);
			
			response.getWriter().println("更新成功");
			
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
				
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
